<?php 
class SchedulesController extends AppController{

	function index(){
		if( $this->data ){
			foreach( $this->data['Schedule'] as $listSchedule ){
				$listSchedule['person_id'] = 1;
				$listSchedule['time'] = json_encode( $listSchedule );
				
				if( ! isset($listSchedule['id']) || $listSchedule['id'] == null )
					$this->Schedule->create();
				
				$this->Schedule->save( $listSchedule );
			}
			
			$this->Session->setFlash( 'Su horario ha sido actualizado con exito.' );
			$this->redirect( 'index' );
		}else{	
			$listSchedules = $this->Schedule->findAllByPersonId( 1 );
			$this->data = $listSchedules;
		
		}
	}
	
	function delete( $intScheduleId ){
		$this->Schedule->id = $intScheduleId;
		$this->Schedule->remove();
		
		$this->Session->setFlash( 'Su horario ha sido actualizado con exito.' );
		$this->redirect( 'index' );
	}


}
?>